<?php
    
    require_once('includes/general.php');
    if(!tep_db_checkDb()) die('ko ket noi dc csdl');
    $content='';
    # menu danh muc san pham
    $sql='select * from tbl_danh_muc_san_pham';
    $kq=tep_db_query($sql);
    $content.='<div id="menu_left">
                  <div class="menu_top"></div>
                  <div class="menu_content">
                    <h2>Danh M?c S?n Ph?m</h2>    ';
                    while($item=tep_db_fetch_array($kq)){
                        $content.='
                            <ul><li><a href="?page=sanpham&amp;madanhmucsanpham='.$item['id'].'">'.$item['ten_danh_muc'].'</a></li></ul>
                        ';
                        
                            
                    }
    $content.='
                    </div>
                    <div class="menu_bottom"></div>
                    <div class="menu_top"></div>                    
                    <div class="menu_content1">
                                <a id="lienhe" href="lienhe.php"><img src="images/contact_card.jpg" alt="" /></a>
                                <a><img src="images/hotline_number.gif" /></a>
                    </div>
                    <div class="menu_bottom"></div>
                </div>
                ';
    #end menu danh muc san pham
    
    # sliding san pham
    
   
            $sql1='select * from tbl_san_pham ';
            $kq1=tep_db_query($sql1);
            $content.='<div id="hinhanhslide">
                        <div id="slides">
                            <div class="slides_container" style="overflow: hidden; position: relative; display: block;">';
            while($item1=tep_db_fetch_array($kq1)){
               
              $content.='  
                
                    
                        <div class="slide">
                            <a href="index.php?page=chitietsanpham&amp;masanpham='.$item1["id"].'&amp;madanhmuc='.$item1["ma_danh_muc"].'&amp;mode=detail"><img src="images/'.$item1['hinh_anh'].'" alt="'.$item1['hinh_anh'].'" style="width:220px; height:250px;margin: 0 50px;"/></a>
                            <div class="caption" >
                                <h2>'.$item1['ten_san_pham'].'</h2>
                                <p>'.$item1['mo_ta_ngan_gon'].'</p> 
                            </div>
                        </div>';
                    
                }
            $content.='</div>	
            <a href="#" class="prev"><img src="images/arrow-prev.png" width="24" height="43" alt="Arrow Prev" /></a>
			<a href="#" class="next"><img src="images/arrow-next.png" width="24" height="43" alt="Arrow Next" /></a>';
        $content.='</div>  <div class="clear"></div> </div>';
        
        #end sliding san pham
    
if(isset($_GET['madanhmucsanpham'])){
    $madanhmuc=$_GET['madanhmucsanpham'];
    $sql2='select ten_danh_muc from tbl_danh_muc_san_pham where id='.$madanhmuc;
    $kq2=tep_db_query($sql2);
    $item2=tep_db_fetch_array($kq2);
    # menu danh muc san pham
    $sql='select * from tbl_danh_muc_san_pham';
    $kq=tep_db_query($sql);
    $content='<div id="menu_left">
                <div class="menu_top"></div>
                  <div class="menu_content">
                    <h2>Danh Mục Sản Phẩm</h2>    ';
    while($item=tep_db_fetch_array($kq)){
        $content.='
            <div class="tendanhmuc"><a href="?page=sanpham&amp;madanhmucsanpham='.$item['id'].'">'.$item['ten_danh_muc'].'</a></div>
        ';
    }
    $content.='</div></div>';
    # cho nay la dem so san pham theo ma danh muc
 $sql4='select count(id) as count from tbl_san_pham where ma_danh_muc='.$madanhmuc;
 $kq4=tep_db_query($sql4);
 $item4=tep_db_fetch_array($kq4);
 $soluongsanpham=$item4['count'];

   
 
     $sql1='select * from tbl_san_pham where ma_danh_muc='.$madanhmuc;
            $kq1=tep_db_query($sql1);
            $content.='<div id="main_content">
                        
                          <h1>'.$item2['ten_danh_muc'].'</h1>';
                          #kiem tra co ton tai san pham nao ko neu co thi thuc hien show ra
                       if($soluongsanpham!=0){    
                        $content.='<div id="sanpham" class="jcarousel-skin-tango">
                            <ul id="sanpham_danhmuc">
                            ';
            while($item1=tep_db_fetch_array($kq1)){
              $content.='  
                    <li><div class="block">
                        <a href="?page=chitietsanpham&amp;masanpham='.$item1['id'].'&amp;madanhmuc='.$item1['ma_danh_muc'].'&amp;mode=detail">
                            <img src="images/'.$item1['hinh_anh'].'" alt="'.$item1['hinh_anh'].'"  />
                        </a>
                        <a href="?page=chitietsanpham&amp;masanpham='.$item1['id'].'&amp;madanhmuc='.$item1['ma_danh_muc'].'&amp;mode=detail"><h2>'.$item1['ten_san_pham'].'</h2></a>
                          						
                        </div>
                    </li>
                    
                    <!--    <div class="sanpham"> 
                            
                            <div class="show_sanpham" >
                                <a href="?page=chitietsanpham&amp;masanpham='.$item1['id'].'&amp;madanhmuc='.$item1['ma_danh_muc'].'&amp;mode=detail">
                                <img src="images/'.$item1['hinh_anh'].'" alt="'.$item1['hinh_anh'].'" style="width:250px; height:250px;margin: 0 50px;"/></a>
                            
                                <a href="?page=chitietsanpham&amp;masanpham='.$item1['id'].'&amp;madanhmuc='.$item1['ma_danh_muc'].'&amp;mode=detail"><h2>'.$item1['ten_san_pham'].'</h2></a>
                                <p>'.$item1['mo_ta_ngan_gon'].'</p> 
                            </div>
                    <!--    </div>  -->';
                    
            
            }
            
            $content.='</ul>';	
            $content.='</div>  <div class="clear"></div>';
              }
              # neu ko co san pham nao thi show thong tin dang cap nhat
             else{
                $content.='Thông Tin Đang Cập Nhật...';}
                        $content.='</div>';

}
    echo $content;
?>